<script setup>
	import FirstTitle from "@comp/FirstTitle";
	import {
		Editor,
		Toolbar
	} from "@wangeditor/editor-for-vue";
	import {
		onMounted
	} from "vue";
	import {
		postTableData
	} from "@/api/table";
	
	import {
		searchDataQbxx
	} from "@/api/search";
	import {
		addOrUpdateQbxx
	} from "@/api/addOrUpdate";


	const city = window.globalObj.name;
	const editorRef = shallowRef();
	const editorRef1 = shallowRef();
	const toolbarConfig = {};
	const toolbarConfig1 = {};
	const editorConfig = {
		placeholder: "请输入内容...",
	};
	const mode = ref("default");
	const mode1 = ref("default");
	
	
	// 加载html
	const initHtml = () => {
		searchDataQbxx({
			m: "能力现状-信息防护系统建设情况"
		}).then((res) => {
			const {
				data
			} = res;
			valueHtml.value = data.find((x) => x.k === "信息防护手段和装备现状")?.v || "";
			valueHtml1.value = data.find((x) => x.k === "信息防护重要目标可用资源现状")?.v || "";
		});
	};
	
	const handleCreated = (editor) => {
		editorRef.value = editor; // 记录 editor 实例，重要！
	};
	const handleCreated1 = (editor) => {
		editorRef1.value = editor; // 记录 editor 实例，重要！
	};
	
	const valueHtml = ref(
		"大庆市人防基本指挥所主要配备了网络安全防护设备和防护软件。具体情况如下："
	);
	
	const valueHtml1 = ref(
		"大庆市重要目标单位配备了防火墙、入侵检测、安全审计等网络安全防护设备和杀毒、防护等软件。具体情况如下："
	);
	
	
	const saveProgramme = () => {
		ElMessageBox.confirm(`确定要保存吗?`, "警告", {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
			customClass: "message-box",
		}).then(() => {
			addOrUpdateQbxx({
					m: "能力现状-信息防护系统建设情况",
					data: [{
						k: "信息防护手段和装备现状",
						v: valueHtml.value,
					}, {
						k: "信息防护重要目标可用资源现状",
						v: valueHtml1.value,
					}],
				})
				.then((result) => {
					if (result.code === 200) {
						ElMessage.success("操作成功");
						initHtml();
					} else {
						ElMessage.error(result.msg);
					}
				})
				.catch(() => {});
		});
	
	}

	
	onBeforeUnmount(() => {
		const editor = editorRef.value;
		const editor1 = editorRef1.value;
		if (!editor) return;
		if (!editor1) return;
		editor.destroy();
		editor1.destroy();
	});

	// 表头单元格样式
	const headerCellStyle = () => {
		return {
			backgroundColor: "#f5f7fa",
			color: "rgba(0,0,0,0.85)",
			fontSize: "14px",
			height: "54px",
		};
	};
	// 单元格样式
	const cellStyle = () => {
		return {
			color: "rgba(0,0,0,0.65)",
			fontSize: "14px",
			lineHeight: "22px",
		};
	};

	const tableData1 = ref([])
	const tableData2 = ref([])

	const getList1 = () => {
	return postTableData({
			docType: "intelligence",
			method: "renfangzhihuifanghushebeisoftware",
		}).then(result => {
			if (result.code === 200) {
				tableData1.value = result?.data || []
			}
		})
	}
	const getList2 = () => {
	return postTableData({
			docType: "intelligence",
			method: "xinxifanghukeyongziyuan",
		}).then(result => {
			if (result.code === 200) {
				tableData2.value = result?.data || []
			}
		})
	}

	onMounted(async () => {
		await initHtml()
		await getList1()
		await getList2()
	});
</script>
<template>
	<div class="">
		<FirstTitle name="信息防护手段和装备现状" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig"
				:mode="mode" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml" :defaultConfig="editorConfig"
				:mode="mode" @onCreated="handleCreated" />
		</div>
		<div class="text-center top-15">{{city}}人防指挥信息系统信息防护设备（软件）统计表</div>
		<el-table id="table" :data="tableData1" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="rowNum" label="序号" width="60" align="center" />
			<el-table-column prop="jd_name" label="行政区划" />
			<el-table-column label="单位名称">
				<el-table-column prop="name" label="单位名称" />
			</el-table-column>
			<el-table-column label="网络安全防护设备">
				<el-table-column prop="firewall" label="防火墙" />
				<el-table-column prop="antivirusSoftware" label="防毒墙" />
				<el-table-column prop="intrusionDetection" label="入侵检测" />
				<el-table-column prop="securityAudit" label="安全审计" />
				<el-table-column prop="securityMachine" label="保密机" />
				<el-table-column prop="shieldingRoom" label="屏蔽室" />
				<el-table-column prop="disasterRecoveryBackup" label="容灾备份" />
			</el-table-column>
			<el-table-column label="安全防护软件">
				<el-table-column prop="antivirusSoftware" label="杀毒软件" />
				<el-table-column prop="protectiveSoftware" label="防护软件" />
			</el-table-column>
		</el-table>

		<FirstTitle name="可用资源现状" class="top-15" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef1" :defaultConfig="toolbarConfig1"
				:mode="mode1" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml1" :defaultConfig="editorConfig"
				:mode="mode1" @onCreated="handleCreated1" />
		</div>
		<div class="text-center top-15">{{city}}信息防护可用资源统计表</div>
		<el-table id="table" :data="tableData2" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="rowNum" label="序号" width="60" align="center" />
			<el-table-column prop="jd_name" label="行政区划(域)" />
			<el-table-column prop="name" label="目标名称" />
			<el-table-column prop="firewall" label="防火墙" />
			<el-table-column prop="antivirusWall" label="防毒墙" />
			<el-table-column prop="intrusionDetection" label="入侵检测" />
			<el-table-column prop="securityAudit" label="安全审计" />
			<el-table-column prop="securityMachine" label="保密机" />
			<el-table-column prop="shieldingRoom" label="屏蔽室" />
			<el-table-column prop="disasterRecoveryBackup" label="容灾备份" />
			<el-table-column prop="antivirusSoftware" label="杀毒软件" />
			<el-table-column prop="protectiveSoftware" label="防护软件" />
		</el-table>

		<div class="flex-justify-end top-20">
			<el-button type="primary" class="save-btn" @click="saveProgramme">保存</el-button>
		</div>
	</div>
</template>
<style scoped lang="scss"></style>